﻿package baseEngine.core
{
    import __AS3__.vec.*;
    import baseEngine.basic.*;
    import baseEngine.materials.*;
    import baseEngine.modifiers.*;
    import baseEngine.system.*;
    import baseEngine.utils.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;
    import frEngine.*;
    import frEngine.animateControler.*;
    import frEngine.animateControler.colorControler.*;
    import frEngine.animateControler.keyframe.*;
    import frEngine.animateControler.particleControler.*;
    import frEngine.animateControler.transformControler.*;
    import frEngine.animateControler.visible.*;
    import frEngine.event.*;
    import frEngine.pools.*;
    import frEngine.shader.*;

    public class Pivot3D extends EventDispatcher implements IPoolObject
    {
        private var _fightObjectControler:FightObjectControler;
        private var _transform:Matrix3D;
        private var _name:String;
        public var priority:int = 0;
        public var layer:int = 0;
        public var lock:Boolean = false;
        private var _children:Vector.<Pivot3D>;
        protected var _visible:Boolean = true;
        private var _invGlobal:Matrix3D;
        private var _parent:Pivot3D;
        protected var _scene:Scene3D;
        private var _inScene:Boolean;
        public var _eventFlags:uint;
        private var _world:Matrix3D;
        private var _updatable:Boolean = false;
        protected var _animateControlerList:Dictionary;
        public var timerContorler:TimeControler;
        public var visibleControler:VisibleControler;
        protected var _curHangControler:Md5SkinAnimateControler;
        private var _pos:Vector3D;
        private var _offsetTransform:Matrix3D;
        private var _rot:Vector3D;
        private var _scale:Vector3D;
        private var _select:Boolean;
        public var worldTransformChanged:Boolean = false;
        private var localTransformChanged:Boolean = false;
        public var _dirtyInv:Boolean = false;
        public var isHide:Boolean = false;
        public var independentRot:Boolean = false;
        public var independentRot2:Boolean = false;
        public var independentScale:Boolean = false;
        public var enabledPool:Boolean = true;
        public var isParticleElement:Boolean = false;
        public var animationMode:int = 1;
        private var _isDisposed:Boolean = false;
        public var isInPool:Boolean = false;
        private var _alpha:Number = 1;
        private var _user:Object;
        protected var _preFrame:uint = 0;
        private static const padToAngle:Number = 57.2958;
        private static const angleTopad:Number = 0.0174533;
        static const MOUSE_OVER:int = 1;
        static const MOUSE_OUT:int = 1 << 1;
        static const PARENT_CHANGE:int = 1 << 2;
        static const EXIT_DRAW_FLAG:int = 1 << 3;
        static const UPDATE_TRANSFORM_FLAG:int = 1 << 4;
        public static const VISIBLE_FLAG:int = 1 << 5;
        public static const PIVOT3D_UPDATE_FLAG:int = 1 << 6;
        public static const SORT_NONE:int = 0;
        public static const SORT_CENTER:int = 1;
        public static const SORT_NEAR:int = 2;
        public static const SORT_FAR:int = 4;
        private static var _temp0:Vector3D = new Vector3D();
        private static var _temp1:Vector3D = new Vector3D();
        private static var _temp2:Vector3D = new Vector3D();
        private static var _dragTarget:Pivot3D;
        private static var _dragStartPos:Vector3D;
        private static var _dragStartDir:Vector3D;
        private static var _dragOffset:Vector3D;
        private static const _matrix:Vector.<Number> = Pivot3D.Vector.<Number>([0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1]);
        private static const deepthMax:int = 30;

        public function Pivot3D(param1:String)
        {
            this._transform = new Matrix3D();
            this._children = new Vector.<Pivot3D>;
            this._invGlobal = new Matrix3D();
            this._world = new Matrix3D();
            this._animateControlerList = new Dictionary(false);
            this._pos = new Vector3D(0, 0, 0, 1);
            this._rot = new Vector3D();
            this._scale = new Vector3D(1, 1, 1, 1);
            this.name = param1;
            this.timerContorler = TimeControler.defaultTimeControler;
            return;
        }// end function

        final public function get isDisposed() : Boolean
        {
            return this._isDisposed;
        }// end function

        public function set alpha(param1:Number) : void
        {
            this._alpha = param1;
            return;
        }// end function

        public function get alpha() : Number
        {
            return this._alpha;
        }// end function

        public function get user() : Object
        {
            return this._user;
        }// end function

        public function set user(param1:Object) : void
        {
            this._user = param1;
            return;
        }// end function

        public function set isDisposed(param1:Boolean) : void
        {
            this._isDisposed = param1;
            return;
        }// end function

        public function set curHangControler(param1:Md5SkinAnimateControler) : void
        {
            this._curHangControler = param1;
            return;
        }// end function

        public function get fightObjectControler() : FightObjectControler
        {
            if (!this._fightObjectControler)
            {
                this._fightObjectControler = this.getAnimateControlerInstance(AnimateControlerType.FightObject) as FightObjectControler;
            }
            return this._fightObjectControler;
        }// end function

        public function get curHangControler() : Md5SkinAnimateControler
        {
            return this._curHangControler;
        }// end function

        public function contains(param1:Pivot3D) : Boolean
        {
            return this._children && this._children.indexOf(param1) != -1;
        }// end function

        final public function get transform() : Matrix3D
        {
            if (this.localTransformChanged)
            {
                this.rebuildTransform();
            }
            return this._transform;
        }// end function

        public function setTransform(param1:Matrix3D, param2:Boolean) : void
        {
            var _loc_3:Vector.<Vector3D> = null;
            var _loc_4:Vector3D = null;
            var _loc_5:Vector3D = null;
            var _loc_6:Vector3D = null;
            if (param1 == null)
            {
                throw new Error("transform不能为空");
            }
            this._transform = param1;
            if (param2)
            {
                _loc_3 = this._transform.decompose();
                _loc_4 = _loc_3[0];
                _loc_5 = _loc_3[1];
                _loc_6 = _loc_3[2];
                this._pos = _loc_4;
                this._pos.w = 1;
                this._rot = _loc_5;
                this._rot.scaleBy(padToAngle);
                this._scale.setTo(_loc_6.x, _loc_6.y, _loc_6.z);
            }
            this.updateTransforms(false, true);
            return;
        }// end function

        public function get name() : String
        {
            return this._name;
        }// end function

        public function set name(param1:String) : void
        {
            this._name = param1;
            return;
        }// end function

        public function get animateControlerList() : Dictionary
        {
            return this._animateControlerList;
        }// end function

        public function hasControler(param1:int) : Boolean
        {
            var _loc_2:Modifier = null;
            if (param1 == -1)
            {
                for each (_loc_2 in this._animateControlerList)
                {
                    
                    return true;
                }
                return false;
            }
            else
            {
                return this._animateControlerList[param1] != null;
            }
        }// end function

        public function removeAnimateControler(param1:int) : void
        {
            var _loc_2:* = this._animateControlerList[param1];
            if (_loc_2 != null)
            {
                _loc_2.dispose();
                delete this._animateControlerList[param1];
            }
            if (param1 == AnimateControlerType.VisibleContoler)
            {
                this.visibleControler.dispose();
                this.visibleControler = null;
            }
            return;
        }// end function

        public function clearAllControlers(param1:Boolean) : void
        {
            var _loc_3:Modifier = null;
            var _loc_4:String = null;
            this._fightObjectControler = null;
            var _loc_2:* = new Array();
            if (param1)
            {
                for each (_loc_3 in this._animateControlerList)
                {
                    
                    _loc_2.push(_loc_3.type);
                    _loc_3.dispose();
                }
                for each (_loc_4 in _loc_2)
                {
                    
                    delete this._animateControlerList[_loc_4];
                }
            }
            else
            {
                this._animateControlerList = new Dictionary(false);
            }
            this.visibleControler = null;
            return;
        }// end function

        public function copyToControlers(param1:Dictionary, param2:VisibleControler) : void
        {
            var _loc_3:Modifier = null;
            if (param2)
            {
                this.getAnimateControlerInstance(param2.type, param2);
            }
            if (!param1)
            {
                return;
            }
            for each (_loc_3 in param1)
            {
                
                this.getAnimateControlerInstance(_loc_3.type, _loc_3);
                _loc_3.toUpdateAnimate(true);
            }
            return;
        }// end function

        public function getAnimateControlerInstance(param1:int, param2:Modifier = null) : Modifier
        {
            var _loc_3:Modifier = null;
            if (param1 == AnimateControlerType.VisibleContoler)
            {
                if (!this.visibleControler)
                {
                    _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(VisibleControler, this));
                    _loc_3.targetObject3d = this;
                    this.visibleControler = VisibleControler(_loc_3);
                }
                return this.visibleControler;
            }
            _loc_3 = this._animateControlerList[param1];
            if (_loc_3 == null)
            {
                switch(param1)
                {
                    case AnimateControlerType.PosX:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(PosXControler, this));
                        break;
                    }
                    case AnimateControlerType.PosY:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(PosYControler, this));
                        break;
                    }
                    case AnimateControlerType.PosZ:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(PosZControler, this));
                        break;
                    }
                    case AnimateControlerType.ScaleX:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(ScaleXControler, this));
                        break;
                    }
                    case AnimateControlerType.ScaleY:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(ScaleYControler, this));
                        break;
                    }
                    case AnimateControlerType.ScaleZ:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(ScaleZControler, this));
                        break;
                    }
                    case AnimateControlerType.ScaleXYZ:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(ScaleXYZControler, this));
                        break;
                    }
                    case AnimateControlerType.RotationX:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(RotationXControler, this));
                        break;
                    }
                    case AnimateControlerType.RotationY:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(RotationYControler, this));
                        break;
                    }
                    case AnimateControlerType.RotationZ:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(RotationZControler, this));
                        break;
                    }
                    case AnimateControlerType.FightObject:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(FightObjectControler, this));
                        break;
                    }
                    case AnimateControlerType.colorAnimateControler:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(ColorControler, this));
                        break;
                    }
                    case AnimateControlerType.LineRoadControler:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(LineRoadControler, this));
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
                if (_loc_3)
                {
                    if (_loc_3 is VisibleControler)
                    {
                        this.visibleControler = _loc_3 as VisibleControler;
                    }
                    else
                    {
                        this._animateControlerList[param1] = _loc_3;
                    }
                    _loc_3.targetObject3d = this;
                }
            }
            return _loc_3;
        }// end function

        public function upload(param1:Scene3D, param2:Boolean = true) : void
        {
            var _loc_3:Pivot3D = null;
            this._scene = param1;
            if (param2)
            {
                for each (_loc_3 in this._children)
                {
                    
                    _loc_3.upload(param1, param2);
                }
            }
            return;
        }// end function

        public function download(param1:Boolean = true) : void
        {
            var _loc_2:Pivot3D = null;
            if (param1)
            {
                for each (_loc_2 in this._children)
                {
                    
                    _loc_2.download(param1);
                }
            }
            return;
        }// end function

        public function copyFrom(param1:Pivot3D) : void
        {
            this.transform.copyFrom(param1.transform);
            this.visible = param1.visible;
            this.layer = param1.layer;
            this.lock = param1.lock;
            return;
        }// end function

        public function clone() : Pivot3D
        {
            var _loc_1:Pivot3D = null;
            var _loc_2:* = new Pivot3D(this.name);
            _loc_2.copyFrom(this);
            for each (_loc_1 in this._children)
            {
                
                if (!_loc_1.lock)
                {
                    _loc_2.addChild(_loc_1.clone());
                }
            }
            return _loc_2;
        }// end function

        public function dispose(param1:Boolean = true) : void
        {
            var _loc_5:Pivot3D = null;
            if (this._isDisposed)
            {
                return;
            }
            this.animationMode = PlayMode.ANIMATION_STOP_MODE;
            this.isParticleElement = false;
            var _loc_2:* = this._children.concat();
            var _loc_3:* = this._children.length;
            this.timerContorler.unActive();
            this.clearAllControlers(true);
            this.parent = null;
            var _loc_4:int = 0;
            while (_loc_4 < _loc_3)
            {
                
                _loc_5 = _loc_2[_loc_4];
                _loc_5.parent = null;
                _loc_4++;
            }
            this._children.length = 0;
            if (this.curHangControler)
            {
                this.curHangControler.removeHang(this);
            }
            this.curHangControler = null;
            this._scene = null;
            this._pos.setTo(0, 0, 0);
            this._rot.setTo(0, 0, 0);
            this._scale.setTo(1, 1, 1);
            this._offsetTransform = null;
            this._transform.identity();
            this._children.length = 0;
            this._invGlobal.identity();
            this._world.identity();
            this._visible = true;
            this._inScene = false;
            this._updatable = false;
            this.worldTransformChanged = false;
            this.localTransformChanged = false;
            this._dirtyInv = false;
            this.isHide = false;
            this.independentRot = false;
            this.independentRot2 = false;
            this.independentScale = false;
            this._select = false;
            this.user = null;
            this.timerContorler = TimeControler.defaultTimeControler;
            FrEventDispatcher.instance.proxyDispatchEvent(this, Engine3dEventName.PIVOT3D_DISPOSE);
            return;
        }// end function

        public function setPosition(param1:Number, param2:Number, param3:Number, param4:Boolean = true) : void
        {
            if (param1 == this._pos.x && param2 == this._pos.y && param3 == this._pos.z)
            {
                return;
            }
            this._pos.setTo(param1, param2, param3);
            if (!param4 && this._parent)
            {
                this._parent.globalToLocal(this._pos, this._pos);
            }
            this._transform.copyColumnFrom(3, this._pos);
            this.updateTransforms(false, true);
            return;
        }// end function

        public function getPosition(param1:Boolean = true, param2:Vector3D = null) : Vector3D
        {
            if (param2 == null)
            {
                param2 = new Vector3D();
            }
            if (param1)
            {
                this.transform.copyColumnTo(3, param2);
            }
            else
            {
                this.world.copyColumnTo(3, param2);
            }
            return param2;
        }// end function

        public function setScale(param1:Number, param2:Number, param3:Number) : void
        {
            var _loc_4:Boolean = false;
            if (this._scale.x != param1)
            {
                this._scale.x = param1;
                _loc_4 = true;
            }
            if (this._scale.y != param2)
            {
                this._scale.y = param2;
                _loc_4 = true;
            }
            if (this._scale.z != param3)
            {
                this._scale.z = param3;
                _loc_4 = true;
            }
            if (_loc_4)
            {
                this.updateTransforms(true, true);
            }
            return;
        }// end function

        public function getScale(param1:Boolean = true, param2:Vector3D = null) : Vector3D
        {
            param2 = Matrix3DUtils.getScale(param1 ? (this.transform) : (this.world), param2);
            return param2;
        }// end function

        public function setRotation(param1:Number, param2:Number, param3:Number) : void
        {
            var _loc_4:Boolean = false;
            if (this._rot.x != param1)
            {
                this._rot.x = param1;
                _loc_4 = true;
            }
            if (this._rot.y != param2)
            {
                this._rot.y = param2;
                _loc_4 = true;
            }
            if (this._rot.z != param3)
            {
                this._rot.z = param3;
                _loc_4 = true;
            }
            if (_loc_4)
            {
                this.updateTransforms(true, true);
            }
            return;
        }// end function

        public function getRotation(param1:Boolean = true, param2:Vector3D = null) : Vector3D
        {
            if (param1)
            {
                param2 = this._rot;
            }
            else
            {
                if (param2 == null)
                {
                    param2 = new Vector3D();
                }
                param2 = Matrix3DUtils.getRotation(this.world, param2);
            }
            return param2;
        }// end function

        public function lookAt(param1:Number, param2:Number, param3:Number, param4:Vector3D = null, param5:Number = 1) : void
        {
            Matrix3DUtils.lookAt(this.transform, param1, param2, param3, param4, param5);
            this.setTransform(this._transform, true);
            return;
        }// end function

        public function setOrientation(param1:Vector3D, param2:Vector3D = null, param3:Number = 1) : void
        {
            Matrix3DUtils.setOrientation(this.transform, param1, param2, param3);
            this.setTransform(this._transform, true);
            return;
        }// end function

        public function setNormalOrientation(param1:Vector3D, param2:Number = 1) : void
        {
            Matrix3DUtils.setNormalOrientation(this.transform, param1, param2);
            this.setTransform(this._transform, true);
            return;
        }// end function

        public function rotateX(param1:Number, param2:Boolean = true, param3:Vector3D = null) : void
        {
            this.rotateAxis(param1, param2 ? (this.getRight(true, _temp2)) : (Vector3D.X_AXIS), param3);
            return;
        }// end function

        public function rotateY(param1:Number, param2:Boolean = true, param3:Vector3D = null) : void
        {
            this.rotateAxis(param1, param2 ? (this.getUp(true, _temp2)) : (Vector3D.Y_AXIS), param3);
            return;
        }// end function

        public function rotateZ(param1:Number, param2:Boolean = true, param3:Vector3D = null) : void
        {
            this.rotateAxis(param1, param2 ? (this.getDir(true, _temp2)) : (Vector3D.Z_AXIS), param3);
            return;
        }// end function

        public function rotateAxis(param1:Number, param2:Vector3D, param3:Vector3D = null) : void
        {
            _temp0.copyFrom(param2);
            _temp0.normalize();
            if (!param3)
            {
                this.transform.copyColumnTo(3, _temp1);
                this.transform.appendRotation(param1, _temp0, _temp1);
            }
            else
            {
                this.transform.appendRotation(param1, _temp0, param3);
            }
            this.setTransform(this._transform, true);
            return;
        }// end function

        public function get x() : Number
        {
            return this._pos.x;
        }// end function

        public function set x(param1:Number) : void
        {
            if (this._pos.x != param1)
            {
                this._pos.x = param1;
                this._transform.copyColumnFrom(3, this._pos);
                this.updateTransforms(false, true);
            }
            return;
        }// end function

        public function get y() : Number
        {
            return this._pos.y;
        }// end function

        public function set y(param1:Number) : void
        {
            if (this._pos.y != param1)
            {
                this._pos.y = param1;
                this._transform.copyColumnFrom(3, this._pos);
                this.updateTransforms(false, true);
            }
            return;
        }// end function

        public function get z() : Number
        {
            return this._pos.z;
        }// end function

        public function set z(param1:Number) : void
        {
            if (this._pos.z != param1)
            {
                this._pos.z = param1;
                this._transform.copyColumnFrom(3, this._pos);
                this.updateTransforms(false, true);
            }
            return;
        }// end function

        public function get pos() : Vector3D
        {
            return this._pos;
        }// end function

        public function get rot() : Vector3D
        {
            return this._rot;
        }// end function

        public function get scale() : Vector3D
        {
            return this._scale;
        }// end function

        public function get rotationX() : Number
        {
            return this._rot.x;
        }// end function

        public function set rotationX(param1:Number) : void
        {
            if (this._rot.x != param1)
            {
                this._rot.x = param1;
                this.updateTransforms(true, true);
            }
            return;
        }// end function

        public function get rotationY() : Number
        {
            return this._rot.y;
        }// end function

        public function set rotationY(param1:Number) : void
        {
            if (this._rot.y != param1)
            {
                this._rot.y = param1;
                this.updateTransforms(true, true);
            }
            return;
        }// end function

        public function get rotationZ() : Number
        {
            return this._rot.z;
        }// end function

        public function set rotationZ(param1:Number) : void
        {
            if (this._rot.z != param1)
            {
                this._rot.z = param1;
                this.updateTransforms(true, true);
            }
            return;
        }// end function

        public function get scaleX() : Number
        {
            return this._scale.x;
        }// end function

        public function set scaleX(param1:Number) : void
        {
            if (this._scale.x != param1)
            {
                this._scale.x = param1;
                this.updateTransforms(true, true);
            }
            return;
        }// end function

        public function get scaleY() : Number
        {
            return this._scale.y;
        }// end function

        public function set scaleY(param1:Number) : void
        {
            if (this._scale.y != param1)
            {
                this._scale.y = param1;
                this.updateTransforms(true, true);
            }
            return;
        }// end function

        public function get scaleZ() : Number
        {
            return this._scale.z;
        }// end function

        public function set scaleZ(param1:Number) : void
        {
            if (this._scale.z != param1)
            {
                this._scale.z = param1;
                this.updateTransforms(true, true);
            }
            return;
        }// end function

        final protected function rebuildTransform() : void
        {
            this.localTransformChanged = false;
            var _loc_1:* = this._rot.length;
            this._transform.identity();
            var _loc_2:Number = 0.0001;
            this._scale.x = 0.0001;
            var _loc_2:Number = 0.0001;
            this._scale.y = 0.0001;
            var _loc_2:Number = 0.0001;
            this._scale.z = 0.0001;
            this._transform.appendScale(this._scale.x, this._scale.y, this._scale.z);
            this._transform.copyColumnFrom(3, this._pos);
            return;
        }// end function

        public function setTranslation(param1:Number = 0, param2:Number = 0, param3:Number = 0, param4:Boolean = true) : void
        {
            Matrix3DUtils.setTranslation(this.transform, param1, param2, param3, param4);
            this.setTransform(this._transform, true);
            return;
        }// end function

        public function translateX(param1:Number, param2:Boolean = true) : void
        {
            Matrix3DUtils.translateX(this.transform, param1, param2);
            this.setTransform(this._transform, true);
            return;
        }// end function

        public function translateY(param1:Number, param2:Boolean = true) : void
        {
            Matrix3DUtils.translateY(this.transform, param1, param2);
            this.setTransform(this._transform, true);
            return;
        }// end function

        public function translateZ(param1:Number, param2:Boolean = true) : void
        {
            Matrix3DUtils.translateZ(this.transform, param1, param2);
            this.setTransform(this._transform, true);
            return;
        }// end function

        public function translateAxis(param1:Number, param2:Vector3D) : void
        {
            Matrix3DUtils.translateAxis(this.transform, param1, param2);
            this.setTransform(this._transform, true);
            return;
        }// end function

        public function copyTransformFrom(param1:Pivot3D, param2:Boolean = true) : void
        {
            if (param2)
            {
                this._transform.copyFrom(param1.transform);
                this.setTransform(this._transform, true);
            }
            else
            {
                this.world = param1.world;
            }
            return;
        }// end function

        public function resetTransforms() : void
        {
            this.transform.identity();
            this.updateTransforms(true, true);
            return;
        }// end function

        public function getRight(param1:Boolean = true, param2:Vector3D = null) : Vector3D
        {
            return Matrix3DUtils.getRight(param1 ? (this.transform) : (this.world), param2);
        }// end function

        public function getLeft(param1:Boolean = true, param2:Vector3D = null) : Vector3D
        {
            return Matrix3DUtils.getLeft(param1 ? (this.transform) : (this.world), param2);
        }// end function

        public function getUp(param1:Boolean = true, param2:Vector3D = null) : Vector3D
        {
            return Matrix3DUtils.getUp(param1 ? (this.transform) : (this.world), param2);
        }// end function

        public function getDown(param1:Boolean = true, param2:Vector3D = null) : Vector3D
        {
            return Matrix3DUtils.getDown(param1 ? (this.transform) : (this.world), param2);
        }// end function

        public function getDir(param1:Boolean = true, param2:Vector3D = null) : Vector3D
        {
            return Matrix3DUtils.getDir(param1 ? (this.transform) : (this.world), param2);
        }// end function

        public function getBackward(param1:Boolean = true, param2:Vector3D = null) : Vector3D
        {
            return Matrix3DUtils.getBackward(param1 ? (this.transform) : (this.world), param2);
        }// end function

        public function localToGlobal(param1:Vector3D, param2:Vector3D = null) : Vector3D
        {
            param2 = param2 || new Vector3D();
            Matrix3DUtils.transformVector(this.world, param1, param2);
            return param2;
        }// end function

        public function localToGlobalVector(param1:Vector3D, param2:Vector3D = null) : Vector3D
        {
            param2 = param2 || new Vector3D();
            Matrix3DUtils.deltaTransformVector(this.world, param1, param2);
            return param2;
        }// end function

        public function globalToLocal(param1:Vector3D, param2:Vector3D = null) : Vector3D
        {
            if (param2 == null)
            {
                param2 = new Vector3D();
            }
            Matrix3DUtils.transformVector(this.invWorld, param1, param2);
            return param2;
        }// end function

        public function globalToLocalVector(param1:Vector3D, param2:Vector3D = null) : Vector3D
        {
            if (param2 == null)
            {
                param2 = new Vector3D();
            }
            Matrix3DUtils.deltaTransformVector(this.invWorld, param1, param2);
            return param2;
        }// end function

        public function getScreenCoords(param1:Vector3D = null, param2:Camera3D = null, param3:Rectangle = null) : Vector3D
        {
            if (!param1)
            {
                param1 = new Vector3D();
            }
            if (!param3 && !this.scene)
            {
                throw new Error("The object isn\'t in the scene");
            }
            if (!param2)
            {
                param2 = Global3D.camera;
            }
            if (!param3)
            {
                param3 = Global3D.scene.viewPort;
            }
            var _loc_4:* = param2.viewProjection.transformVector(this.getPosition(false, param1));
            var _loc_5:* = param3.width * 0.5;
            var _loc_6:* = param3.height * 0.5;
            param1.x = _loc_4.x / _loc_4.w * _loc_5 + _loc_5 + param3.x;
            param1.y = (-_loc_4.y) / _loc_4.w * _loc_6 + _loc_6 + param3.y;
            param1.z = _loc_4.z;
            param1.w = _loc_4.w;
            return param1;
        }// end function

        private function removeRotFromMatrix(param1:Matrix3D, param2:Matrix3D) : Matrix3D
        {
            var _loc_3:* = param1.decompose("quaternion");
            if (this.independentRot)
            {
                _loc_3[1].x = 0;
                _loc_3[1].y = 0;
                _loc_3[1].z = 0;
                _loc_3[1].w = 1;
            }
            if (this.independentScale)
            {
                _loc_3[2].x = 1;
                _loc_3[2].y = 1;
                _loc_3[2].z = 1;
            }
            param2.recompose(_loc_3, "quaternion");
            return param2;
        }// end function

        public function set offsetTransform(param1:Matrix3D) : void
        {
            if (param1 == this._offsetTransform)
            {
                return;
            }
            this._offsetTransform = param1;
            this.updateTransforms(false, true);
            return;
        }// end function

        public function get offsetTransform() : Matrix3D
        {
            return this._offsetTransform;
        }// end function

        public function identityOffsetTransform() : void
        {
            if (this._offsetTransform)
            {
                this._offsetTransform = null;
                this.updateChildrenTransform();
            }
            return;
        }// end function

        final public function get world() : Matrix3D
        {
            var _loc_1:Boolean = false;
            var _loc_2:Vector.<Vector3D> = null;
            var _loc_3:Vector3D = null;
            var _loc_4:Vector3D = null;
            var _loc_5:Vector3D = null;
            var _loc_6:Vector3D = null;
            if (this.localTransformChanged || this.worldTransformChanged)
            {
                if (this.localTransformChanged)
                {
                    this.rebuildTransform();
                }
                this._world.copyFrom(this._transform);
                _loc_1 = false;
                if (this._parent)
                {
                    if (this.independentRot || this.independentRot2)
                    {
                        _loc_2 = this._parent.world.decompose();
                        _loc_3 = _loc_2[0];
                        _loc_4 = _loc_2[1];
                        _loc_5 = _loc_2[2];
                        _loc_3.incrementBy(this._pos);
                        _loc_3.w = 0;
                        if (this.independentRot)
                        {
                            _loc_4.x = this._rot.x * angleTopad;
                            _loc_4.y = this._rot.y * angleTopad;
                            _loc_4.z = this._rot.z * angleTopad;
                        }
                        if (this.independentScale)
                        {
                            _loc_5.x = this._scale.x;
                            _loc_5.y = this._scale.y;
                            _loc_5.z = this._scale.z;
                            _loc_5.w = 0;
                        }
                        _loc_1 = true;
                    }
                    else
                    {
                        this._world.append(this._parent.world);
                        if (this.independentScale)
                        {
                            _loc_2 = this._world.decompose();
                            _loc_6 = _loc_2[2];
                            _loc_6.x = this._scale.x;
                            _loc_6.y = this._scale.y;
                            _loc_6.z = this._scale.z;
                            _loc_6.w = 0;
                            _loc_1 = true;
                        }
                    }
                }
                if (_loc_1)
                {
                    try
                    {
                        this._world.recompose(_loc_2);
                    }
                    catch (e:Error)
                    {
                    }
                }
                this.worldTransformChanged = false;
                this._dirtyInv = true;
            }
            return this._world;
        }// end function

        final public function set world(param1:Matrix3D) : void
        {
            this.transform.copyFrom(param1);
            if (this.parent)
            {
                this._transform.append(this.parent.invWorld);
            }
            this.setTransform(this._transform, true);
            this.updateTransforms(true, true);
            return;
        }// end function

        public function get invWorld() : Matrix3D
        {
            if (this._dirtyInv || this.localTransformChanged || this.worldTransformChanged)
            {
                this._invGlobal.copyFrom(this.world);
                this._invGlobal.invert();
                this._dirtyInv = false;
            }
            return this._invGlobal;
        }// end function

        public function updateTransforms(param1:Boolean, param2:Boolean, param3:int = 0) : void
        {
            if (param3 > deepthMax)
            {
                throw new Error("updateTransforms出错了，堆栈过多!");
            }
            this.worldTransformChanged = true;
            if (param1)
            {
                this.localTransformChanged = true;
            }
            if (this._eventFlags & UPDATE_TRANSFORM_FLAG)
            {
                FrEventDispatcher.instance.proxyDispatchEvent(this, Engine3dEventName.UPDATE_TRANSFORM_EVENT);
            }
            if (param2)
            {
                this.updateChildrenTransform(param3);
            }
            return;
        }// end function

        public function updateChildrenTransform(param1:int = 0) : void
        {
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_5:Pivot3D = null;
            if (this._children)
            {
                _loc_2 = param1 + 1;
                _loc_3 = this._children.length;
                _loc_4 = 0;
                for each (_loc_5 in this._children)
                {
                    
                    _loc_5.updateTransforms(false, true, _loc_2);
                    _loc_4++;
                    if (_loc_4 >= _loc_3)
                    {
                        break;
                    }
                }
            }
            this.worldTransformChanged = true;
            return;
        }// end function

        final public function get children() : Vector.<Pivot3D>
        {
            return this._children;
        }// end function

        final public function get parent() : Pivot3D
        {
            return this._parent;
        }// end function

        final public function set parent(param1:Pivot3D) : void
        {
            var _loc_4:int = 0;
            if (param1 == this._parent)
            {
                return;
            }
            if (param1 && (this._isDisposed || this.isInPool))
            {
                throw new Error("出错了，已被销毁！");
            }
            var _loc_2:* = param1;
            var _loc_3:int = 0;
            while (_loc_2 && _loc_3 < deepthMax)
            {
                
                if (_loc_2 == this)
                {
                    throw new Error("当前要指定的父类对像是该对你像的孙子，不能指定为父类！");
                }
                _loc_3++;
                _loc_2 = _loc_2._parent;
            }
            if (this._curHangControler && this._curHangControler.targetObject3d != param1)
            {
                this._curHangControler.removeHang(this);
            }
            var _loc_5:* = this._parent;
            this._parent = param1;
            if (_loc_5)
            {
                _loc_4 = _loc_5._children.indexOf(this);
                if (_loc_4 != -1)
                {
                    _loc_5._children.splice(_loc_4, 1);
                }
            }
            if (param1)
            {
                _loc_4 = param1._children.indexOf(this);
                if (_loc_4 == -1)
                {
                    param1._children.push(this);
                    this.updateChildrenTransform();
                }
            }
            if (!this._inScene)
            {
                if (param1)
                {
                    if (param1 is Scene3D)
                    {
                        this.addedToScene(param1 as Scene3D);
                    }
                    else if (param1._inScene)
                    {
                        this.addedToScene(param1.scene);
                    }
                }
            }
            else if (!param1)
            {
                this.removedFromScene();
            }
            else if (!(param1 is Scene3D) && !param1._inScene)
            {
                this.removedFromScene();
            }
            if (this._eventFlags & PARENT_CHANGE)
            {
                FrEventDispatcher.instance.proxyDispatchEvent(this, Engine3dEventName.PARENT_CHANGE_EVENT);
            }
            return;
        }// end function

        public function addedToScene(param1:Scene3D) : Boolean
        {
            var _loc_2:Pivot3D = null;
            if (this._isDisposed)
            {
                return false;
            }
            this._scene = param1;
            this._inScene = true;
            var _loc_3:* = this._children.length;
            var _loc_4:int = 0;
            for each (_loc_2 in this._children)
            {
                
                _loc_2.addedToScene(this._scene);
                _loc_4++;
                if (_loc_4 >= _loc_3)
                {
                    break;
                }
            }
            return true;
        }// end function

        public function removedFromScene() : void
        {
            var _loc_1:Pivot3D = null;
            if (!this._scene)
            {
                return;
            }
            this._scene = null;
            this._inScene = false;
            FrEventDispatcher.instance.proxyDispatchEvent(this, Engine3dEventName.REMOVED_FROM_SCENE_EVENT);
            for each (_loc_1 in this._children)
            {
                
                _loc_1.removedFromScene();
            }
            return;
        }// end function

        public function addChild(param1:Pivot3D) : Pivot3D
        {
            if (param1.parent == this)
            {
                return param1;
            }
            param1.parent = this;
            return param1;
        }// end function

        public function removeChild(param1:Pivot3D) : Pivot3D
        {
            param1.parent = null;
            return param1;
        }// end function

        public function getChildByName(param1:String, param2:int = -1, param3:Boolean = true) : Pivot3D
        {
            var _loc_4:Pivot3D = null;
            var _loc_5:Pivot3D = null;
            for each (_loc_4 in this._children)
            {
                
                if (_loc_4.name == param1 && param2-- < 0)
                {
                    return _loc_4;
                }
                if (param3)
                {
                    _loc_5 = _loc_4.getChildByName(param1, _loc_2, param3);
                    if (_loc_5)
                    {
                        return _loc_5;
                    }
                }
            }
            return null;
        }// end function

        public function update(param1:int = 0) : void
        {
            var _loc_5:Pivot3D = null;
            var _loc_2:* = param1 + 1;
            if (_loc_2 > deepthMax)
            {
                throw new Error("update 出错了，堆栈过多!");
            }
            if (this._isDisposed || this.isInPool)
            {
                throw new Error("出错了，已被回了或销毁，无法进行更新!");
            }
            if (TimeControler.stageTime == this._preFrame)
            {
                return;
            }
            this._preFrame = TimeControler.stageTime;
            if (this.visibleControler)
            {
                this.visibleControler.toUpdateAnimate();
            }
            if (this._visible)
            {
                this.toUpdateModifier();
            }
            if (this._eventFlags & PIVOT3D_UPDATE_FLAG)
            {
                FrEventDispatcher.instance.proxyDispatchEvent(this, Engine3dEventName.PIVOT3D_UPDATE);
            }
            var _loc_3:int = 0;
            var _loc_4:* = this._children.length;
            for each (_loc_5 in this._children)
            {
                
                _loc_5.update(_loc_2);
                if (_loc_3 >= _loc_4)
                {
                    break;
                }
                _loc_3++;
            }
            return;
        }// end function

        protected function toUpdateModifier() : void
        {
            var _loc_2:Modifier = null;
            var _loc_1:int = 0;
            for each (_loc_2 in this._animateControlerList)
            {
                
                _loc_2.toUpdateAnimate();
                if (_loc_1 > deepthMax)
                {
                    break;
                }
                _loc_1++;
            }
            return;
        }// end function

        final public function get visible() : Boolean
        {
            return this._visible;
        }// end function

        final public function set visible(param1:Boolean) : void
        {
            var _loc_3:Pivot3D = null;
            if (this._visible == param1)
            {
                return;
            }
            var _loc_2:* = this._visible;
            this._visible = param1;
            if (this._eventFlags & VISIBLE_FLAG && _loc_2 != param1)
            {
                FrEventDispatcher.instance.proxyDispatchEvent(this, Engine3dEventName.VISIBLE_CHANGE_EVENT);
            }
            return;
        }// end function

        final public function get scene() : Scene3D
        {
            return this._scene;
        }// end function

        public function draw(param1:Boolean = true, param2:ShaderBase = null) : void
        {
            var _loc_3:Pivot3D = null;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            if (param1)
            {
                _loc_4 = this._children.length;
                _loc_5 = 0;
                for each (_loc_3 in this._children)
                {
                    
                    _loc_5++;
                    _loc_3.draw(param1, param2);
                    if (_loc_5 >= _loc_4)
                    {
                        break;
                    }
                }
            }
            if (this._eventFlags & EXIT_DRAW_FLAG)
            {
                FrEventDispatcher.instance.proxyDispatchEvent(this, Engine3dEventName.EXIT_DRAW_EVENT);
            }
            return;
        }// end function

        public function get inView() : Boolean
        {
            return true;
        }// end function

        public function setLayer(param1:int, param2:Boolean = true) : void
        {
            var _loc_3:Pivot3D = null;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            this.layer = param1;
            if (param2)
            {
                _loc_4 = this._children.length;
                _loc_5 = 0;
                for each (_loc_3 in this._children)
                {
                    
                    _loc_3.setLayer(param1, param2);
                    _loc_5++;
                    if (_loc_5 >= _loc_4)
                    {
                        break;
                    }
                }
            }
            return;
        }// end function

        public function forEach(param1:Function, param2:Class = null, param3:Object = null, param4:Boolean = true) : void
        {
            var _loc_5:Pivot3D = null;
            for each (_loc_5 in this._children)
            {
                
                if (!param2)
                {
                    if (param3)
                    {
                        this.param1(_loc_5, param3);
                    }
                    else
                    {
                        this.param1(_loc_5);
                    }
                }
                else if (_loc_5 is param2)
                {
                    if (param3)
                    {
                        this.param1(_loc_5, param3);
                    }
                    else
                    {
                        this.param1(_loc_5);
                    }
                }
                if (param4)
                {
                    _loc_5.forEach(param1, param2, param3, param4);
                }
            }
            return;
        }// end function

        public function getMaterialByName(param1:String, param2:Boolean = true) : Material3D
        {
            var _loc_3:Pivot3D = null;
            var _loc_4:Material3D = null;
            if (param2)
            {
                for each (_loc_3 in this._children)
                {
                    
                    _loc_4 = _loc_3.getMaterialByName(param1, param2);
                    if (_loc_4)
                    {
                        return _loc_4;
                    }
                }
            }
            return null;
        }// end function

        override public function addEventListener(param1:String, param2:Function, param3:Boolean = false, param4:int = 0, param5:Boolean = false) : void
        {
            var _loc_6:* = this._eventFlags;
            switch(param1)
            {
                case Engine3dEventName.MOUSE_OVER:
                {
                    this._eventFlags = this._eventFlags | MOUSE_OVER;
                    break;
                }
                case Engine3dEventName.MOUSE_OUT:
                {
                    this._eventFlags = this._eventFlags | MOUSE_OUT;
                    break;
                }
                case Engine3dEventName.PARENT_CHANGE_EVENT:
                {
                    this._eventFlags = this._eventFlags | PARENT_CHANGE;
                    break;
                }
                case Engine3dEventName.EXIT_DRAW_EVENT:
                {
                    this._eventFlags = this._eventFlags | EXIT_DRAW_FLAG;
                    break;
                }
                case Engine3dEventName.UPDATE_TRANSFORM_EVENT:
                {
                    this._eventFlags = this._eventFlags | UPDATE_TRANSFORM_FLAG;
                    break;
                }
                case Engine3dEventName.VISIBLE_CHANGE_EVENT:
                {
                    this._eventFlags = this._eventFlags | VISIBLE_FLAG;
                    break;
                }
                case Engine3dEventName.PIVOT3D_UPDATE:
                {
                    this._eventFlags = this._eventFlags | PIVOT3D_UPDATE_FLAG;
                    break;
                }
                default:
                {
                    break;
                }
            }
            if (this._eventFlags & 3)
            {
                this.updatable = true;
            }
            super.addEventListener(param1, param2, param3, param4, param5);
            return;
        }// end function

        override public function removeEventListener(param1:String, param2:Function, param3:Boolean = false) : void
        {
            super.removeEventListener(param1, param2, param3);
            switch(param1)
            {
                case Engine3dEventName.MOUSE_OVER:
                {
                    if (!hasEventListener(param1))
                    {
                        this._eventFlags = this._eventFlags | MOUSE_OVER;
                        this._eventFlags = this._eventFlags - MOUSE_OVER;
                    }
                    return;
                }
                case Engine3dEventName.MOUSE_OUT:
                {
                    if (!hasEventListener(param1))
                    {
                        this._eventFlags = this._eventFlags | MOUSE_OUT;
                        this._eventFlags = this._eventFlags - MOUSE_OUT;
                    }
                    return;
                }
                case Engine3dEventName.PARENT_CHANGE_EVENT:
                {
                    if (!hasEventListener(param1))
                    {
                        this._eventFlags = this._eventFlags | PARENT_CHANGE;
                        this._eventFlags = this._eventFlags - PARENT_CHANGE;
                    }
                    return;
                }
                case Engine3dEventName.EXIT_DRAW_EVENT:
                {
                    if (!hasEventListener(param1))
                    {
                        this._eventFlags = this._eventFlags | EXIT_DRAW_FLAG;
                        this._eventFlags = this._eventFlags - EXIT_DRAW_FLAG;
                    }
                    return;
                }
                case Engine3dEventName.UPDATE_TRANSFORM_EVENT:
                {
                    if (!hasEventListener(param1))
                    {
                        this._eventFlags = this._eventFlags | UPDATE_TRANSFORM_FLAG;
                        this._eventFlags = this._eventFlags - UPDATE_TRANSFORM_FLAG;
                    }
                    return;
                }
                case Engine3dEventName.VISIBLE_CHANGE_EVENT:
                {
                    if (!hasEventListener(param1))
                    {
                        this._eventFlags = this._eventFlags | VISIBLE_FLAG;
                        this._eventFlags = this._eventFlags - VISIBLE_FLAG;
                    }
                    return;
                }
                case Engine3dEventName.PIVOT3D_UPDATE:
                {
                    if (!hasEventListener(param1))
                    {
                        this._eventFlags = this._eventFlags | PIVOT3D_UPDATE_FLAG;
                        this._eventFlags = this._eventFlags - PIVOT3D_UPDATE_FLAG;
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function get updatable() : Boolean
        {
            return this._updatable;
        }// end function

        public function set updatable(param1:Boolean) : void
        {
            if (param1 == this._updatable)
            {
                return;
            }
            this._updatable = param1;
            return;
        }// end function

        public function set select(param1:Boolean) : void
        {
            if (this._select == param1)
            {
                return;
            }
            this._select = param1;
            if (this._select)
            {
                FrEventDispatcher.instance.proxyDispatchEvent(this, Engine3dEventName.MOUSE_OVER);
            }
            else
            {
                FrEventDispatcher.instance.proxyDispatchEvent(this, Engine3dEventName.MOUSE_OUT);
            }
            return;
        }// end function

    }
}
